/**
 * 
 */
package ns.gflex.services

import java.util.List;

import org.hibernate.criterion.CriteriaSpecification;

import ns.gflex.domain.*;
import ns.gflex.domain.association.*;

/**
 * @author neo
 *
 */
class DictionaryService extends GFlexService {
	Boolean isSystemAdmin(){
		return list([eq:[['user', sessionUser]],role:[eq:[
					[
						'roleCode',
						'Administrators']
				]]],UserRole)
	}

	List getDepartmentList(){
		Department.list()
	}
	List getAllUserList(){
		listEnabled([eq:[['editable', true]]],User)
	}
	List getAllRoleList(){
		listEnabled(null,Role)
	}
	List getUserRoles(String account){
		UserRole.findAllByUser(User.findByAccount(account))*.role
	}
	List getParamList(){
		Param.list()
	}
	List getParamTypeList(){
		ParamType.list()
	}
	
	List getLabelList(){
		logHost("getLabelList")
		Label.withCriteria {
			projections{
				groupProperty 'label', 'label'
				count 'id', 'numbers'
			}
			order 'numbers', 'desc'
			maxResults 200
			resultTransformer CriteriaSpecification.ALIAS_TO_ENTITY_MAP
		}*.label
	}

	List getHotLabelList(){
		logHost("getHotLabelList")
		Label.withCriteria {
			projections{
				groupProperty 'label', 'label'
				count 'id', 'numbers'
			}
			order 'numbers', 'desc'
			maxResults 30
			resultTransformer CriteriaSpecification.ALIAS_TO_ENTITY_MAP
		}
	}
}
